import sys

import datetime

sys.path.append('..')
from source.all_monitor_parallel.meterManagerParallel import MeterManagerParallel
from source.auth.identity import Identity
date_now_1 = datetime.datetime.now()
token = Identity().getToken()
mm = MeterManagerParallel()
base_data = mm.getBaseData(token)
if base_data.count(None) == 0:
    print "get base data success"
else:
    print "get base data fail"
data = mm.getMetricsAllParallel(base_data, token)
if data.count(None) == 0:
    print "get data success"
else:
    print "get data fail"

print "###########taotao"
for data_tmp in data:
    if data_tmp:
        for resource_id , meters in data_tmp.iteritems():
            if meters:
                for key,val in meters.iteritems():
                    print '%s-%s-%s' % (resource_id,key,val)
union_data = mm.union_data(data)
for resource_id , meters in union_data.iteritems():
    print resource_id
    for meter in meters:
        print meter
aggregate_data =  mm.aggregate_data(union_data)
for resource_id , meters in aggregate_data.iteritems():
    print resource_id
    for meter in meters.iteritems():
        print meter
mm.storeMetrics(aggregate_data)

date_now_2 = datetime.datetime.now()
print 'All Time resumes:'
print date_now_2 - date_now_1